package com.jt.ktdemo.adapter

import android.content.Context
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jt.ktdemo.R
import com.jt.ktdemo.bean.RcMessage

class ReportMessageDetailAdapter (layoutResId: Int, data: ArrayList<RcMessage>, context: Context) :
    BaseQuickAdapter<RcMessage, BaseViewHolder>(layoutResId, data) {

    private var datas = ArrayList<RcMessage>()
    private var aContext: Context? = null

    init {
        aContext = context
        datas = data
    }

    override fun convert(helper: BaseViewHolder, item: RcMessage) {
        //消息内容
        helper.setText(R.id.tvModuleContext, item.message)

        //消息时间
        helper.setText(R.id.tvModuleDate, item.createTimeNew)

        //图片
        if (item.url.startsWith("http")) {
            Glide.with(aContext!!).load(item.url)
                .into((helper.getView<View>(R.id.ivModule) as ImageView))
        }

        //背景图
        if (item.messageType.equals("report")) {
            Glide.with(aContext!!).load(R.drawable._0)
                .into((helper.getView<View>(R.id.ivModule) as ImageView))
        }else if (item.messageType.equals("system")){
            Glide.with(aContext!!).load(R.drawable._1)
                .into((helper.getView<View>(R.id.ivModule) as ImageView))
        }
    }

    fun addListData(data: MutableList<RcMessage>) {
        val size = datas.size
        datas.addAll(size, data)
        notifyItemRangeChanged(size, data.size)
    }
}